<?php
 include("include/textcenter.php");
 include("include/db.php");
 $id = $_GET["id"];
 $did = $_GET["did"];
 
 if ($id > 0 && $did > 0) {
    $del = mysql_query("DELETE FROM vnf_shop_order_item WHERE OrderID='$id' AND ProductNo = '$did'");
 }
 
$result = mysql_query("SELECT o.*, c.*, cp.* from vnf_shop_order o
            left JOIN vnf_customer c ON o.user_id = c.CustomerNo
            left JOIN vnf_coupon cp ON o.coupon_code = cp.CouponID
             where order_id ='$id'");
?>
<html>
<head>
<meta name="description" content="Admin<?php echo $tagdescription?>">
<meta name="keywords" content="<?php echo $tagkeywords?> Main">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title><?php echo $tagtitle?></title>

<script type="text/javascript" src="simpletreemenu.js">
/***********************************************
* Simple Tree Menu- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<link rel="stylesheet" type="text/css" href="simpletree.css" />
<LINK rel="StyleSheet" href="include/css_classes.css" type="text/css">
 <script src="jquery.min.js" type="text/javascript" charset="utf-8"></script>
 <script language="javascript">
	$(function(){
		//alert('111');
		$('#addproduct').hide();
		$('#click').click(function(){
			$('#addproduct').toggle();
		})
	})                
            </script>
    <script type="text/javascript" src="jquery-1.4.2.js"></script>
	<script type='text/javascript' src='jquery.autocomplete.js'></script>
	<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
	<script type="text/javascript">
		$(function(){
			$("#Product").autocomplete("docomplete1.php", {
				width: 260,
				matchContains: true,				
            });
			
			$("#Product").result(function(event, data, formatted) {
				$("#ProductID").val(data[1]);
			});

		});
	</script>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" link="#0000FF" vlink="#800080" alink="#FF0000" bgcolor="#FFFFFF">
<!-- -------------------Header---------------------------- -->
<?php include("include/header.php"); ?>
<!-- -------------------End Header---------------------------- -->


<div align="center">
<table border="0" cellspacing="0" cellpadding="0" width="90%">

	<tr>
		<td width="12%" valign="top">
		<img border="0" src="public/images/homepage/spider16.gif" width="200" height="1"></td>
		<td width="1%" valign="top">
		<img border="0" src="public/images/homepage/spider16.gif" width="16" height="1"></td>
		<td width="86%" valign="top">
		<img border="0" src="public/images/homepage/spider16.gif" width="16" height="1"></td>
	</tr>	
	<tr>
		<!-- ///////////////////Begin Leftmenu/////////////////// -->
		<td width="12%" valign="top" bgcolor="#FFFFFF">
		<?php include("include/leftmenu.php"); ?>
		</td>
		<!-- ///////////////////End Leftmenu/////////////////// -->
		
		<td width="1%" valign="top" background="public/images/homepage/16.gif">&nbsp;</td>
		<td width="86%" valign="top">
<!-- -------------------Begin Body---------------------------- -->
<p class="title16B">&nbsp;<a href="order_list.php">Order</a> 
<div id="printthis"> 
<table  width="100%" width="70%" cellspacing="0" cellpadding="2" bordercolor="#FFECFF">
<?php
while($row = mysql_fetch_array($result))
{
    /*echo "<pre>";
    print_r($row);
    echo "</pre>";*/
    $odate_created = strtotime($row['date_created']);
    $sdate_created= date("Y-m-d",$odate_created);
 ?>
 <script type="text/javascript"> 
var win=null;
function printIt()
{
     $.ajax({
        type: "GET",
        url: "order_update_printYN.php?id=<?php echo $row['order_id'] ?>",
        success: function() {
        }
    });
    //$('#showdate').show();
	win = window.open();
	self.focus();
	win.document.open();
	win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
	win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
	win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'><br><br><br>');
	win.document.write($('#printthis').html());
	win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
	win.document.close();
	win.print();
	//win.close();
    //$('#showdate').hide();
}
</script> 
<tr style="border: 0 !important;">
		<td colspan="2">
            <div style="float: left; width:50%" align="left">
			BILL TO:<br />
			<?php echo $row['BillToName'] ?><br/>
			<?php echo $row['BillToAddress'] ?><br/>
			<?php echo $row['BillToCity'] ?> &nbsp;
			<?php echo $row['BillToState'] ?>&nbsp;
			<?php echo $row['BillToZipCode'] ?><br/>
			<?php echo $row['BillToCountry'] ?>
			</div>
            <div style="float: left; width:50%;">
                SHIP TO:<br />
    			<?php echo $row['ShipToFirstName'].' '. $row['ShipToLastName'] ?><br/>
    			<?php echo $row['ShipToAddress'] ?><br/>
    			<?php echo $row['ShipToCity'] ?> &nbsp;
    			<?php echo $row['ShipToState'] ?>&nbsp;
    			<?php echo $row['ShipToZipCode'] ?><br/>
    			<?php echo $row['ShipToCountry'] ?>
            </div>
		</td>
		
	</tr>
    <tr>
		<td colspan ="2">
			<table border="1" style="width: 100%; margin-top:20px;">
				<tr>
					<td>
						Oder Date
					</td>
					<td>
						Status
					</td>
					<td>
						Ship Date
					</td>
					<td>
						Payment By
					</td>
					<td>
						Confirmation No
					</td>
					<td>
					Shipment Tracking
					</td>
				</tr>
				<tr>
					<td>&nbsp;
						<?php echo $sdate_created;?> 
					</td>
					<td>&nbsp;
						<?php echo $row['order_status'];?> 
					</td>
					<td>&nbsp;
						<?php echo date("Y-m-d",strtotime($row['ShipDate']));?> 
					</td>
					<td>&nbsp;
						<?php echo $row['PaymentMethod'];?> 
					</td>
					<td>&nbsp;
						<?php echo $row['ConfirmationNo'];?> 
					</td>
					<td>&nbsp;
						<?php echo $row['ShipMent'];?> 
					</td>
				</tr>
			</table>
        </td>
        </tr>
        <tr>
            <td colspan="2">
             
            <table style="border-top: 1px solid #DBD2C8; width:100%;" align="right">
               <tr>
                <td>
                 <?php
                if(isset($_POST['additem']))
                {
                    $ProID = $_POST['ProductID'];
                    $Quantity = $_POST['Quantity'];
                    $Order = $_POST['OrderID'];
                    $sqlselectpro = "select Product, SKU, Price from vnf_product where ProductNo=".$ProID;
                    //echo $sqlselectpro;
                    $product = mysql_query($sqlselectpro);
                    while ($p = mysql_fetch_array($product))
                    {
                        $sqladd = "insert into vnf_shop_order_item(`OrderID`, `ProductNo`, `SKU`, `Product`, `Attribute`, `Quantity`, `Price`, `date_cretaed`) values('".$Order."', '".$ProID."', '".$p['SKU']."', '".$p['Product']."', 'NULL', $Quantity, '".$p['Price']."', '".date('Y-m-d H:i:s', time())."')";
                       
                        mysql_query($sqladd);
                        //echo '<meta http-equiv="Refresh" content="0;URL=order_detail.php?id='. $row['order_id'].'" />';
                        $result = mysql_query("SELECT o.*, c.*, cp.* from vnf_shop_order o
                            left JOIN vnf_customer c ON o.user_id = c.CustomerNo
                            left JOIN vnf_coupon cp ON o.coupon_code = cp.CouponID
                             where order_id ='$id'");
                        $row = mysql_fetch_array($result);

                    } 
                }
            ?>
                  <script language="javascript">
                 $('#addproduct').hide();
                $('#click').click(function(){
                    $('#addproduct').toggle();
                })
            </script>
            <div id="click"><b style="color: blue; font-size: 18px; cursor: pointer;">+Add Product</b></div>
            <div id="addproduct">
            <fieldset style="width: 300px;">
             <legend>
            <b style="font-size:14px;"> Add new product </b>
            </legend>
            <form method="post" action="">
            
                <table>
                    <tr>
                        <td>
                            ProductNo
                        </td>
                        <td>
                            <input type="text" name="Product" id="Product" />
                            <input type="hidden" name="ProductID" id="ProductID" />
                            <input type="hidden" name="OrderID" id="OrderID" value="<?php echo $row['order_id'] ?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Quantity
                        </td>
                        <td>
                            <input type="text" name="Quantity" id="Quantity" value="1" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="submit" name="additem" id="additem" value="Add" />
                        </td>
                    </tr>
                </table>
            </form>
            </fieldset>
            </div>
                </td>
               </tr>
				<tr>
                    <td colspan="6">
                    <form method="post" action="">
                    <table style="width: 100%;">
                <tr>
					<td>
						Quantity
					</td>
					<td>
						SKU
					</td>
					<td>
						Description
					</td>
					<td>
						Price
					</td>
					<td>
						Total
					</td>
				</tr>
                     <?php
                        $item = mysql_query("Select * from vnf_shop_order_item where OrderID='$id'");
                if(count($item)>0) 
                {
                    $subTotal = 0;
                    while($detail = mysql_fetch_array($item))
                    {
                    ?>
                     <?php
                        $subtotal = 0;
                        $total = $detail['Quantity'] * $detail['Price'];
                        $subTotal += $total;
                        if(isset($_POST['updatequantity']))
                        {
                        //print_r($_POST['ProductNo']);
                             //$ProductNo = $_POST['ProductNo'];
                            $Quantity = $_POST['Quantity' . $detail['ProductNo']];
                            $Price = $_POST['Price'. $detail['ProductNo']];
                            $sql = "Update vnf_shop_order_item set `Quantity` =  '".$Quantity."', `Price` =  '".$Price."' where ProductNo={$detail['ProductNo']} AND OrderID = {$row['order_id']}";
                            mysql_query($sql);
                            //echo '<meta http-equiv="Refresh" content="0;URL=order_detail.php?id='. $row['order_id'].'" />';
                        }
                    } // while
        $item = mysql_query("Select * from vnf_shop_order_item where OrderID='$id'");
        $subTotal = 0;
        while($detail = mysql_fetch_array($item))
        {
                        $subtotal = 0;
                        $total = $detail['Quantity'] * $detail['Price'];
                        $subTotal += $total;
                ?>
                    <tr>
					<td>
                        <a href="order_detail.php?id=<?=$id?>&did=<?=$detail['ProductNo']?>">Delete</a>
						<input style="width: 50px;" type="text" id="Quantity<?=$detail['ProductNo']?>" name="Quantity<?=$detail['ProductNo']?>" value="<?php echo $detail['Quantity'];?>" />
                        <input type="hidden" id="ProductNo" name="ProductNo<?=$detail['ProductNo']?>" value="<?php echo $detail['ProductNo']?>" />
					</td>
					<td>
						<?php echo $detail['SKU'];?> 
					</td>
					<td>
						<?php echo $detail['Product'];?> 
					</td>
					<td>
                        <input style="width: 120px;" type="text" id="Price<?=$detail['ProductNo']?>" name="Price<?=$detail['ProductNo']?>" value="<?php echo $detail['Price'];?>" />
                       
					</td>
					<td>
						<?php
                        echo $total;?> 
					</td>
                    </tr>
                    <?php
        }
        }
    ?>
                    <tr>
                    <td colspan="5" style="text-align: right;">
                        <input type="submit" name="updatequantity" value="Update" />
                    </td>
                    </tr>
                    </table>
                     
                    </form>
                    </td>
				</tr>
            </table>
    
    </td>
    </tr>
    <tr>
        <td colspan="2">
            <!--<table align="right">
				<tr>
				<td align="right">
                <div align="right" style="margin-top: 20px;">-->
                <?php
                    if(isset($_POST['updateorder']))
                    {
                         $order_id = $_POST['order_id'];
                         //$Subtotal =$_POST['Subtotal'];
                         $ShipMethod = $_POST['ShipMethod'];
                         $ShippingCost =$_POST['ShippingCost'];
                         $Tax = $_POST['Tax'];
                         $coupon_value = $_POST['coupon_value'];
                         $StoreCreditAmount = $_POST['StoreCreditAmount'];
                         $GiftCardAmount = $_POST['GiftCardAmount'];
                         //$total = $_POST['total']; ,`total` =  '".$total."'
                         $GiftWrapYN = $_POST['GiftWrapYN'];
                         $StaffMessage = $_POST['StaffMessage'];
                        $sql = "Update vnf_shop_order set `Subtotal` =  '".$Subtotal."', 
                        `ShipMethod` =  '".$ShipMethod."', `ShippingCost` =  '".$ShippingCost."', `Tax` =  '".$Tax."', 
                        `coupon_value` =  '".$coupon_value."', `StoreCreditAmount` =  '".$StoreCreditAmount."', `GiftCardAmount` =  '".$GiftCardAmount."', `GiftWrapYN` =  '".$GiftWrapYN."',  `StaffMessage` =  '".$StaffMessage."' 
                         where order_id = $order_id";
                        mysql_query($sql);
                        echo '<meta http-equiv="Refresh" content="0;URL=order_detail.php?id='. $row['order_id'].'" />';
                    } 
                ?>
                
                <table style="float: right; text-align: right; width:100%;">
                     <form method="post" action="">
                    <tr>
                        <td colspan="2" style="text-align: right; color:red">
                        <?php
                            echo $row['CouponTitle'];
                        ?>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Subtotal
                        </td>
                        <td width="150">
                        <?=$subTotal?>
                        <!--input style="width: 120px; text-align: right;" type="text" id="Subtotal" name="Subtotal" value="<?php echo $row['Subtotal'];?>" /-->
                        <input type="hidden" id="order_id" name="order_id" value="<?php echo $row['order_id']?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        <input style="width: 120px; " type="hidden" id="ShipMethod" name="ShipMethod" value="<?php echo $row['ShipMethod'];?>" />  Shipping
                        </td>
                        <td>
                        <input style="width: 120px; text-align: right;" type="text" id="ShippingCost" name="ShippingCost" value="<?php echo $row['ShippingCost'];?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Sales Tax
                        </td>
                        <td>
                        <input style="width: 120px; text-align: right;" type="text" id="Tax" name="Tax" value="<?php echo $row['Tax'];?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Coupon
                        </td>
                        <td>
                        <input style="width: 120px; text-align: right;" type="text" id="coupon_value" name="coupon_value" value="<?php echo $row['coupon_value'];?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Store Credit
                        </td>
                        <td>
                        <input style="width: 120px; text-align: right;" type="text" id="StoreCreditAmount" name="StoreCreditAmount" value="<?php echo $row['StoreCreditAmount'];?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        GiftCard
                        </td>
                        <td>
                        <input style="width: 120px; text-align: right;" type="text" id="GiftCardAmount" name="GiftCardAmount" value="<?php echo $row['GiftCardAmount'];?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        TOTAL DUE
                        </td>
                        <td>
                        <?php
                            $totalDue = $subTotal + $row['ShippingCost'] + $row['Tax'] - $row['coupon_value'] - $row['StoreCreditAmount'] - $row['GiftCardAmount'];
                            
                            if ($totalDue < 0) {
                                $totalDue = 0;
                            }
                            $sql = "Update vnf_shop_order set `totao` =  '".$totalDue."' where order_id = $order_id";
                            mysql_query($sql);
                            echo $totalDue;
                        ?>
                        
                        <!--input style="width: 120px; text-align: right;" type="text" id="total" name="total" value="<?php echo $row['total'];?>" /-->
                        </td>
                    </tr>
                     <tr>
                        <td>
                        GiftWrapYN
                        </td>
                        <td>
                             <select size="1" name="GiftWrapYN">
                            <?php
                            ?>
                                <option value="1" <?php if($row['GiftWrapYN'] == 1) { echo "selected";}?>>Yes</option>
                                <option value="0" <?php if($row['GiftWrapYN'] == 0) { echo "selected";}?>>No</option>
                			</select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        Staff Message
                        </td>
                        <td>
                        <input style="width: 120px; text-align: right;" type="text" id="StaffMessage" name="StaffMessage" value="<?php echo $row['StaffMessage'];?>" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <input type="submit" name="updateorder" value="Update" />
                        </td>
                    </tr>
                    </form>
                </table>
                
                <!--</div>
				</td>
				</tr>
			</table>-->
              </td>
       	</tr> 
           <tr>
            <td>
                 <input type="hidden" name="id" value="<?php echo $row['order_id'] ?>" />
            </td>
           </tr>  
</table>
</div>

<table>
    <tr>
        <td colspan="2">
            <br />
            <div>
        <?php
             if(isset($_POST['submitUpdate']))
            {
                 $id = $_POST['id'];
                 //$shipdate = $_POST['ShipDate'];
                 $shipperno = $_POST['ShipNo'];
                $sql = "Update vnf_shop_order set `ShipNo` =  '".$shipperno."', `order_status` =  '2', `ShipDateUpdate` = '".date('Y-m-d H:i:s', time())."'  where order_id='$id'";
                mysql_query($sql);
                //echo '<meta http-equiv="Refresh" content="0;URL=index.php?com=order&func=detail&id='. $row['order_id'].'" />';
            }
        ?>
             <fieldset style="border:1px solid #cccccc;padding-left:10px;padding-bottom:0px; margin-bottom:10px; width:50%;">
             <legend>
            <b style="font-size:14px;"> Shipping </b>
            </legend>
            <br />
            <form method="post" action="">
            Method: 	<?php echo $row['ShipMethod'];?><input type="hidden" id="id" name="id" value="<?php echo $row['order_id']?>" /><br /><br />
            <?php
                if($row['ShipDateUpdate'] == '0000-00-00 00:00:00') 
                {
             ?>
            Ship Date: 	<input readonly="true" type="tex" id="ShipDate" name="ShipDate" value="<?php echo $row['ShipDate'];?>" /> &nbsp; Shipper No: <input type="text" id="ShipNo" name="ShipNo" value="<?php echo $row['ShipNo'];?>" /><br />
            <?php
                }
                else
                {
            ?>
            Ship Date: 	<input readonly="true" type="tex" id="ShipDate" name="ShipDate" value="<?php echo $row['ShipDateUpdate'];;?>" /> &nbsp; Shipper No: <input type="text" id="ShipNo" name="ShipNo" value="<?php echo $row['ShipNo'];?>" /><br />
            <?php
                }
            ?>
            <input type="submit" value="Ship Invoice" id="submitUpdate" name="submitUpdate" />
             </form>
            </fieldset>
        </div>
        <br />
         <div>
            <fieldset style="border:1px solid #cccccc;padding-left:10px;padding-bottom:0px; margin-bottom:10px; width:50%;">
             <legend>
            <b style="font-size:14px;">Credit card information </b>
            </legend>
            <br />
            <div style="margin-bottom: 10px;">
            <?php echo $row['PaymentMethod'];?>: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['MasterCard'];?>	<br /><br />
            Expiration Date: 	<?php echo $row['ExpirationDate'];?> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CVV:<b style="color: #F9F;"><?php echo $row['CVV'];?></b>
            </div>
            </fieldset>
        </div>
        <br />
         <span style="padding: 0px 20px;"><a  href="javascript:printIt();">Print</a></span>
         </td> 
    </tr>
</table>
<?php
    }
   // mysql_close($con);
?>


<!-- -------------------End Body---------------------------- -->

&nbsp;</td>
	</tr>

</table>
</div>
<!-- ----------------------------------------------- -->
<!-- \\\\\\\\\\\\\\\\\\\\\Begin Footer\\\\\\\\\\\\\\\\\\\\\ -->
<?php include("include/footer.php"); ?>
<!-- \\\\\\\\\\\\\\\\\\\\\End Footer\\\\\\\\\\\\\\\\\\\\\ -->
</body>

</html>